package se.webbzon.boltzmann.game.object.platform;

import java.nio.ByteBuffer;

import se.webbzon.oschi01.friendly.Friendly;
import se.webbzon.oschi01.worldeditor.WorldStaticObjectDeflation;
import se.webbzon.oschi01.worldobject.WorldObject;

public class PlatformShadowDeflation extends WorldStaticObjectDeflation {
	
	private PlatformShadowShape shape;
	
	/*============================================================
	Constructors
	============================================================*/

	public PlatformShadowDeflation(int deflationProperties, WorldObject[] dependencies) {
		super(deflationProperties,dependencies);
	}
	
	public PlatformShadowDeflation(int deflationProperties, PlatformShadow shadow, Platform parent) {
		super(	deflationProperties,
				(parent == null) ? null : new Platform[] {parent},
				shadow);
		shape = shadow.getShape();
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	@Override public void inflate(ByteBuffer buff) {
		super.inflate(buff);
		shape = PlatformShadowShape.values()[buff.getInt()];
	}

	@Override public ByteBuffer deflate(int allocate) {
		ByteBuffer buff = super.deflate(allocate + 4);
		buff.putInt(shape.ordinal());
		return buff;
	}
	
	/*============================================================
	Friendly Methods
	============================================================*/
	
	@Friendly PlatformShadow makePlatformShadow() {
		final Platform platform;
		if (dependencies() > 0)
			platform = (Platform) getDependency(0);
		else
			platform = null;
		PlatformShadow shadow = new PlatformShadow(platform,shape);
		shadow.setPosition(getX(), getY(), getZ());
		shadow.setSize(getWidth(), getHeight(), getDepth());
		shadow.setRotation(getEX(), getEY(), getEZ(), getAngle());
		return shadow;
	}

}
